package com.tm.fiverole.controller;

import com.tm.fiverole.entity.MenuEntity;
import com.tm.fiverole.result.Result;
import com.tm.fiverole.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangSang
 * @create 2022-08-18 21:11
 */
@RestController
@RequestMapping("menu")
public class MenuController {


    @Autowired
    private MenuService menuService;

    //添加注释
    @PreAuthorize("hasPermission('query','送')")
    @GetMapping("queryMeun")
    public Result queryMeun(){

        return menuService.queryMenuAll();
    }
    //添加注释
    @PostMapping("postMenu")
    public Result postMenu(@RequestBody MenuEntity menuEntity){

        return menuService.postMenu(menuEntity);

    }
    //添加注释
    @PutMapping("updateMenu")
    public Result updateMenu(@RequestBody MenuEntity menuEntity){

        return menuService.updateMenu(menuEntity);
    }

    @DeleteMapping("deleteMenu/{id}")
    public  Result deleteMenu(@PathVariable Integer id ){


        // 异常捕获 测试代码
      /*  if(true){
            throw  new RuntimeException();
        }*/
        return menuService.deleteMenu(id);
    }


}
